function count_same_elements(collection) {
  let object={};
  let arr=[];
  for(let item of collection){
    if(item.length===1){
      if(!object[item]){
      object[item]={};
      object[item].name=item;
      object[item].summary=1;
    }
    else {
      object[item].summary++;
    }
   }
   else if((item.length===3)||(item.length===4)) {
    let arr1=item.split("");
    if(!object[arr1[0]]){
     object[arr1[0]]={};
     object[arr1[0]].name=arr1[0];
     object[arr1[0]].summary=parseInt(arr1[2]);
    }
    else{
      object[arr1[0]].summary=object[arr1[0]].summary + parseInt(arr1[2]);
    }
   } 
   else if(item.length===5){
    let arr2=item.split("[");
    let arr3=arr2[1].split("]");
    if(!object[arr2[0]]){
      object[arr2[0]]={};
      object[arr2[0]].name=arr2[0];
      object[arr2[0]].summary=parseInt(arr3[0]);
     }
     else{
       object[arr2[0]].summary=object[arr2[0]].summary+parseInt(arr3[0]);
     }
   }
  }
  for(let i in object){
    arr.push(object[i]);
  }
  return arr;
}

module.exports = count_same_elements;
